# Archlive <http://archlive-pkg.googlecode.com>
pkgname=busybox
pkgver=1.14.2
pkgrel=3
pkgdesc="Utilities for rescue and embedded systems, with HTTPd support"
arch=("i686" "x86_64")
url="http://busybox.net"
license=('GPL')
makedepends=("make" "gcc" "sed" "ncurses")
replaces=("tar" "sed" "cpio" "coreutils" "syslogd" "time" "patch" "wget" "diffutils" "unzip" "findutils" "eject" "dcron" "vi" "gzip")
provides=("tar" "sed" "cpio" "coreutils" "syslogd" "time" "patch" "wget" "diffutils" "unzip" "findutils" "eject" "dcron" "vi" "gzip")
options=()
source=($url/downloads/$pkgname-$pkgver.tar.bz2 config \
	busybox-httpd busybox-httpd-rc busybox-httpd-watch httpd.conf httpd-rc.conf
)
md5sums=(c13b09b4125688d5fca5c95a79bf814a
	89f98f29c73c67b1a829d57a44d72c81
	3bdf984a53c1361bc2a28ff33542ea74
	46c0e5fa50b84d93cb34d7bc2563e34a
	d897aba2f008d911c97a837f9645ffc9
	d8ae5de2c6a10a1b68c85304bf58da72
	41e20b684539b665bce653a64aa37972
)

build() {
  cd "$srcdir/$pkgname-$pkgver"
#  cp $srcdir/patches/$pkgname-$pkgver.config $srcdir/$pkgname-$pkgver/.config
  cp $srcdir/config $srcdir/$pkgname-$pkgver/.config
  # if you want to run menuconfig uncomment the following line:
  # make menuconfig
  make || return 1
  make install
  cp -r $srcdir/$pkgname-$pkgver/_install/* $pkgdir/
  mkdir $pkgdir/bin
  install -m755 busybox $pkgdir/bin/

  mkdir -p $pkgdir/etc/rc.d
  #ln -s /etc/rc.d $pkgdir/etc/init.d
  cp $srcdir/patches/busybox.conf $pkgdir/etc
  chmod 600 $pkgdir/etc/busybox.conf
  cp $srcdir/patches/dnsd.conf $pkgdir/etc
  cp $srcdir/patches/udhcpd.conf $pkgdir/etc
  touch $pkgdir/etc/resolv.conf
  cp $srcdir/patches/inetd.conf $pkgdir/etc
  cp $srcdir/patches/dnsd $pkgdir/etc/rc.d
  cp $srcdir/patches/udhcpd $pkgdir/etc/rc.d
  cp $srcdir/patches/inetd $pkgdir/etc/rc.d
  cp $srcdir/patches/zcip $pkgdir/etc/rc.d
  #cp $srcdir/patches/init $pkgdir
  rm $pkgdir/linuxrc
  mkdir -p $pkgdir/etc/modprobe.d
  # Udhcpc stuff.
  mkdir -p $pkgdir/usr/share/udhcpc
  cp $srcdir/patches/udhcp.script $pkgdir/usr/share/udhcpc/default.script
  chmod +x $pkgdir/usr/share/udhcpc/default.script
  # ZeroConf stuff.
  cp $srcdir/patches/zcip.script $pkgdir/etc
  cp -r $srcdir/patches/applications $pkgdir/usr/share

  cd $srcdir
  mkdir -p "$pkgdir"/usr/bin
  mkdir -p "$pkgdir"/etc/rc.d
  mkdir -p "$pkgdir"/etc/busybox
  
  cp busybox-httpd "$pkgdir"/usr/bin/
  cp busybox-httpd-watch "$pkgdir"/usr/bin/
  cp busybox-httpd-rc "$pkgdir"/etc/rc.d/busybox-httpd
  cp httpd.conf "$pkgdir"/etc/busybox
  cp httpd-rc.conf "$pkgdir"/etc/busybox
  chmod -R 755 "$pkgdir"
  #protect potential passwords
  chown -R root:http "$pkgdir"/etc/busybox/httpd.conf
  chmod -R 740 "$pkgdir"/etc/busybox/httpd.conf
}